const { json } = require('express');
var express = require('express');
var router = express.Router();
const ordersApi = require("../api/order")

// 订单列表
router.get('/orderList', async function (req, res, next) {
  const { curPage, eachPage } = req.query;
  const data = await ordersApi.getorder({ curPage, eachPage });
  res.send(data);
});

// 新增订单接口
router.post('/addorder', async function (req, res, next) {
  const orderdata = req.body;
  const data = await ordersApi.addorder(orderdata);
  console.log(data);
  res.send(data);
});

// 根据电影查询订单
router.get('/searchMove', async function (req, res, next) {
  const { moveName } = req.query;
  const data = await ordersApi.searchMove(moveName);
  res.send(data);
});


// 获取对应排片下所有座位
router.get('/orderseat', async function (req, res, next) {
  const { schedules } = req.query;
  const data = await ordersApi.getseating(schedules);
  res.send(data);
});

// 座位修改状态
router.post('/changestatus', async function (req, res, next) {
  const { _id, status } = req.body;
  console.log(_id, status);
  const data = await ordersApi.changeseating( _id ,status );
  res.send(data);
});

// 获取莫一个座位
router.get('/getseatingOne', async function (req, res, next) {
  const { _id } = req.query;
  const data = await ordersApi.getseatingOne(_id );
  res.send(data);
});


module.exports = router;